.class public Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;
.super Lorg/apache/http/entity/mime/content/AbstractContentBody;
.source "LengthStreamBody.java"


# instance fields
.field private final filename:Ljava/lang/String;

.field private final in:Ljava/io/InputStream;

.field private left_data:J

.field private final length:J

.field private send_length:J


# direct methods
.method public constructor <init>(Ljava/io/InputStream;Ljava/lang/String;J)V
    .locals 6

    const-string v2, "application/octet-stream"

    move-object v0, p0

    move-object v1, p1

    move-object v3, p2

    move-wide v4, p3

    .line 11
    invoke-direct/range {v0 .. v5}, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;-><init>(Ljava/io/InputStream;Ljava/lang/String;Ljava/lang/String;J)V

    return-void
.end method

.method public constructor <init>(Ljava/io/InputStream;Ljava/lang/String;JJ)V
    .locals 6

    const-string v2, "application/octet-stream"

    move-object v0, p0

    move-object v1, p1

    move-object v3, p2

    move-wide v4, p3

    .line 8
    invoke-direct/range {v0 .. v5}, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;-><init>(Ljava/io/InputStream;Ljava/lang/String;Ljava/lang/String;J)V

    .line 9
    iput-wide p5, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->send_length:J

    .line 10
    iput-wide p3, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->left_data:J

    return-void
.end method

.method public constructor <init>(Ljava/io/InputStream;Ljava/lang/String;Ljava/lang/String;J)V
    .locals 2

    .line 1
    invoke-direct {p0, p2}, Lorg/apache/http/entity/mime/content/AbstractContentBody;-><init>(Ljava/lang/String;)V

    const-wide/16 v0, -0x1

    .line 2
    iput-wide v0, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->send_length:J

    const-wide/16 v0, 0x0

    .line 3
    iput-wide v0, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->left_data:J

    if-eqz p1, :cond_0

    .line 4
    iput-object p1, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->in:Ljava/io/InputStream;

    .line 5
    iput-object p3, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->filename:Ljava/lang/String;

    .line 6
    iput-wide p4, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->length:J

    return-void

    .line 7
    :cond_0
    new-instance p1, Ljava/lang/IllegalArgumentException;

    const-string p2, "Input stream may not be null"

    invoke-direct {p1, p2}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V

    throw p1
.end method


# virtual methods
.method public getCharset()Ljava/lang/String;
    .locals 1

    const/4 v0, 0x0

    return-object v0
.end method

.method public getContentLength()J
    .locals 5

    .line 1
    iget-wide v0, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->send_length:J

    const-wide/16 v2, -0x1

    cmp-long v4, v0, v2

    if-nez v4, :cond_0

    .line 2
    iget-wide v0, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->length:J

    return-wide v0

    .line 3
    :cond_0
    iget-wide v2, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->left_data:J

    cmp-long v4, v2, v0

    if-lez v4, :cond_1

    goto :goto_0

    :cond_1
    move-wide v0, v2

    :goto_0
    return-wide v0
.end method

.method public getFilename()Ljava/lang/String;
    .locals 1

    .line 1
    iget-object v0, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->filename:Ljava/lang/String;

    return-object v0
.end method

.method public getInputStream()Ljava/io/InputStream;
    .locals 1

    .line 1
    iget-object v0, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->in:Ljava/io/InputStream;

    return-object v0
.end method

.method public getTransferEncoding()Ljava/lang/String;
    .locals 1

    const-string v0, "binary"

    return-object v0
.end method

.method public writeTo(Ljava/io/OutputStream;)V
    .locals 10
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    const-string v0, "LengthStream"

    .line 2
    iget-wide v1, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->send_length:J

    const-wide/16 v3, -0x1

    cmp-long v5, v1, v3

    if-eqz v5, :cond_0

    .line 3
    invoke-virtual {p0, p1}, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->writeTo2(Ljava/io/OutputStream;)V

    return-void

    :cond_0
    if-eqz p1, :cond_6

    const/16 v1, 0x4000

    :try_start_0
    new-array v2, v1, [B

    const-wide/16 v3, 0x0

    const/4 v5, 0x0

    const/4 v6, 0x0

    .line 4
    :catch_0
    :cond_1
    :goto_0
    iget-wide v7, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->length:J

    cmp-long v9, v3, v7

    if-gez v9, :cond_4

    iget-object v7, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->in:Ljava/io/InputStream;

    rsub-int v8, v6, 0x4000

    invoke-virtual {v7, v2, v6, v8}, Ljava/io/InputStream;->read([BII)I

    move-result v7

    const/4 v8, -0x1

    if-ne v7, v8, :cond_2

    goto :goto_1

    :cond_2
    add-int/2addr v6, v7

    const/16 v8, 0x400

    if-le v6, v8, :cond_3

    .line 5
    invoke-virtual {p1, v2, v5, v6}, Ljava/io/OutputStream;->write([BII)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_1
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    const/4 v6, 0x0

    :cond_3
    int-to-long v8, v7

    add-long/2addr v3, v8

    const/4 v8, 0x1

    if-ne v7, v8, :cond_1

    const-wide/16 v7, 0x14

    .line 6
    :try_start_1
    invoke-static {v7, v8}, Ljava/lang/Thread;->sleep(J)V
    :try_end_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_0
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    goto :goto_0

    :cond_4
    :goto_1
    if-eqz v6, :cond_5

    .line 7
    :try_start_2
    new-instance v1, Ljava/lang/StringBuilder;

    const-string v3, "last send:"

    invoke-direct {v1, v3}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v1, v6}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-static {v0, v1}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    .line 8
    invoke-virtual {p1, v2, v5, v6}, Ljava/io/OutputStream;->write([BII)V

    .line 9
    :cond_5
    invoke-virtual {p1}, Ljava/io/OutputStream;->flush()V
    :try_end_2
    .catch Ljava/lang/Exception; {:try_start_2 .. :try_end_2} :catch_1
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    .line 10
    :goto_2
    iget-object p1, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->in:Ljava/io/InputStream;

    invoke-virtual {p1}, Ljava/io/InputStream;->close()V

    return-void

    :catchall_0
    move-exception p1

    goto :goto_3

    :catch_1
    move-exception p1

    :try_start_3
    const-string v1, "occur exception"

    .line 11
    invoke-static {v0, v1}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    .line 12
    invoke-virtual {p1}, Ljava/lang/Exception;->printStackTrace()V
    :try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_0

    goto :goto_2

    .line 13
    :goto_3
    iget-object v0, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->in:Ljava/io/InputStream;

    invoke-virtual {v0}, Ljava/io/InputStream;->close()V

    .line 14
    throw p1

    .line 15
    :cond_6
    new-instance p1, Ljava/lang/IllegalArgumentException;

    const-string v0, "Output stream may not be null"

    invoke-direct {p1, v0}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V

    goto :goto_5

    :goto_4
    throw p1

    :goto_5
    goto :goto_4
.end method

.method public writeTo(Ljava/io/OutputStream;I)V
    .locals 0
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .annotation runtime Ljava/lang/Deprecated;
    .end annotation

    .line 1
    invoke-virtual {p0, p1}, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->writeTo(Ljava/io/OutputStream;)V

    return-void
.end method

.method public writeTo2(Ljava/io/OutputStream;)V
    .locals 13
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    if-eqz p1, :cond_e

    .line 1
    iget-wide v0, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->left_data:J

    iget-wide v2, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->send_length:J

    cmp-long v4, v0, v2

    if-lez v4, :cond_0

    move-wide v0, v2

    :cond_0
    const/16 v2, 0x4000

    const-wide/16 v3, 0x0

    :try_start_0
    new-array v5, v2, [B
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_2
    .catchall {:try_start_0 .. :try_end_0} :catchall_1

    const/4 v6, 0x0

    move-wide v7, v0

    const/4 v9, 0x0

    :cond_1
    :goto_0
    cmp-long v10, v7, v3

    if-gtz v10, :cond_2

    goto :goto_1

    :cond_2
    rsub-int v10, v9, 0x4000

    int-to-long v10, v10

    cmp-long v12, v10, v7

    if-lez v12, :cond_3

    move-wide v10, v7

    .line 2
    :cond_3
    :try_start_1
    iget-object v12, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->in:Ljava/io/InputStream;

    long-to-int v11, v10

    invoke-virtual {v12, v5, v9, v11}, Ljava/io/InputStream;->read([BII)I

    move-result v10

    const/4 v11, -0x1

    if-ne v10, v11, :cond_8

    :goto_1
    cmp-long v2, v7, v3

    if-gtz v2, :cond_7

    if-eqz v9, :cond_4

    .line 3
    invoke-virtual {p1, v5, v6, v9}, Ljava/io/OutputStream;->write([BII)V

    .line 4
    :cond_4
    invoke-virtual {p1}, Ljava/io/OutputStream;->flush()V

    .line 5
    iget-wide v5, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->left_data:J

    sub-long/2addr v5, v0

    iput-wide v5, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->left_data:J
    :try_end_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_0
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    cmp-long p1, v5, v3

    if-eqz p1, :cond_5

    cmp-long p1, v7, v3

    if-lez p1, :cond_6

    .line 6
    :cond_5
    iget-object p1, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->in:Ljava/io/InputStream;

    invoke-virtual {p1}, Ljava/io/InputStream;->close()V

    :cond_6
    return-void

    .line 7
    :cond_7
    :try_start_2
    new-instance p1, Ljava/lang/Exception;

    invoke-direct {p1}, Ljava/lang/Exception;-><init>()V

    throw p1

    :catchall_0
    move-exception p1

    move-wide v0, v7

    goto :goto_3

    :catch_0
    move-exception p1

    move-wide v0, v7

    goto :goto_2

    :cond_8
    add-int/2addr v9, v10

    const/16 v11, 0x400

    if-le v9, v11, :cond_9

    .line 8
    invoke-virtual {p1, v5, v6, v9}, Ljava/io/OutputStream;->write([BII)V
    :try_end_2
    .catch Ljava/lang/Exception; {:try_start_2 .. :try_end_2} :catch_0
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    const/4 v9, 0x0

    :cond_9
    int-to-long v11, v10

    sub-long/2addr v7, v11

    const/4 v11, 0x1

    if-ne v10, v11, :cond_1

    const-wide/16 v10, 0x14

    .line 9
    :try_start_3
    invoke-static {v10, v11}, Ljava/lang/Thread;->sleep(J)V
    :try_end_3
    .catch Ljava/lang/Exception; {:try_start_3 .. :try_end_3} :catch_1
    .catchall {:try_start_3 .. :try_end_3} :catchall_0

    goto :goto_0

    :catch_1
    nop

    goto :goto_0

    :catchall_1
    move-exception p1

    goto :goto_3

    :catch_2
    move-exception p1

    :goto_2
    :try_start_4
    const-string v2, "LengthStream"

    const-string v5, "occur exception"

    .line 10
    invoke-static {v2, v5}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    .line 11
    invoke-virtual {p1}, Ljava/lang/Exception;->printStackTrace()V
    :try_end_4
    .catchall {:try_start_4 .. :try_end_4} :catchall_1

    .line 12
    iget-wide v5, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->left_data:J

    cmp-long p1, v5, v3

    if-eqz p1, :cond_a

    cmp-long p1, v0, v3

    if-lez p1, :cond_b

    .line 13
    :cond_a
    iget-object p1, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->in:Ljava/io/InputStream;

    invoke-virtual {p1}, Ljava/io/InputStream;->close()V

    :cond_b
    return-void

    .line 14
    :goto_3
    iget-wide v5, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->left_data:J

    cmp-long v2, v5, v3

    if-eqz v2, :cond_c

    cmp-long v2, v0, v3

    if-lez v2, :cond_d

    .line 15
    :cond_c
    iget-object v0, p0, Lcom/estrongs/android/pop/netfs/utils/LengthStreamBody;->in:Ljava/io/InputStream;

    invoke-virtual {v0}, Ljava/io/InputStream;->close()V

    .line 16
    :cond_d
    throw p1

    .line 17
    :cond_e
    new-instance p1, Ljava/lang/IllegalArgumentException;

    const-string v0, "Output stream may not be null"

    invoke-direct {p1, v0}, Ljava/lang/IllegalArgumentException;-><init>(Ljava/lang/String;)V

    goto :goto_5

    :goto_4
    throw p1

    :goto_5
    goto :goto_4
.end method
